<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>NexHome Admin</title>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
     <!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    <!--<link href="css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />-->

    <!-- libraries -->
   <link href="css/lib/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" />
    <link href="css/lib/font-awesome.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/layout.css" />
    <link rel="stylesheet" type="text/css" href="css/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/icons.css" />
	
	   
    
   <!-- this page specific styles -->
    <link rel="stylesheet" href="css/compiled/index.css" type="text/css" media="screen" /> 
	<link rel="stylesheet" href="css/bootstrap-table.min.css"> 
   <!-- open sans font -->
    <link href='css/OpenSans.css' rel='stylesheet' type='text/css' />

    <!-- lato font -->
    <link href='css/Lato.css' rel='stylesheet' type='text/css' />
	
<!--[if lt IE 9]>
      <script src="js/html5.js"></script>
    <![endif]--> 
	 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	 <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="Cache" content="no-cache">
	 <style>
	 a{cursor:pointer}
	a {
  color: #0088cc;
  text-decoration: none;
} 	
#main-stats .stat {
text-align: right;
padding: 15px 0px 15px 0px;
border-right: 1px solid #e8e9ee;
position: relative;
box-shadow: 1px 0px 0px 0px white;
}
.header .avatar {
float: left;
margin-right: 25px;
border: 2px solid #e9ecee;
position: relative;
top: 3px;
}
.header .name {
font-weight: 600;
margin: 20px 0 8px 0;
line-height: 26px;
margin-bottom: 10px;
float: none;
}
.header span.area {
color: #7d848c;
font-style: italic;
font-size: 14px;
}
	 </style>
	<script>

	var currRid;
	var currRsn;
	var isReLoad = false;
	var CurrRouterSnOnline = false;
	var ChoosedUsermap;
	var userObj;
	var currBindUsers = [];
function requestID()
{ 
	var url = location.href;
	var paraString;
	if(url.indexOf("devid") != -1){ 
 	paraString = url.substring(url.indexOf("=")+1,url.length);	 
	}
	else{
	paraString = "NO";
	}
	return paraString;  	
	
}
function GetCurrBindUsers()
{
    $.ajax({                
                url: '../orgMgr/user/getBindUsers', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{devId: currRid},               
				error : function() {
				 alert("获取数据异常，请重新获取"); 
				},    
                success: function(data){
					if(data.resultCode != '10000'){
						currBindUsers = [];
						//TODO
						bootbox.alert(data.resultMsg, function() {					
						//return;
						});	
						
					}
					else{
						currBindUsers = eval(data.resultMsg);	
						$('#table-userlist').bootstrapTable('refresh');							
					}
					 
				}
				   
     })
}
function FindDevList()
{
	var username = $("#Dtext").val();
	username = '100000101156';
	var jsonData;	
	 $.ajax({                 
				//url : '../../device.do?action=loadDeviceListByKey',  
				url : '../../manager/device.do?action=searchActivate',  
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{sKey: username},                
				error : function() {
					alert("查询连接超时...");				
				},    
                success: devinfosuccFunction
				   
            })
}
	</script>
  </head>

  <body> 
  <!--<![endif]-->
  <!-- main container -->
    <div class="content">       
        <div class="container-fluid">
		
		 <!-- upper main stats -->
            <!--<div id="main-stats">
                <div class="row-fluid stats-row">
                    <div class="span4 stat">
                        <div class="data"  align="center">
                            <a href="#router"><span class="number">路由器信息</span></a>
                            
                        </div>
                        
                    </div>
                    <div class="span4 stat">
                        <div class="data" align="center">
                            <a href="#subprofile"><span class="number">子设备信息</span></a>
                            
                        </div>
                        
                    </div>
                    <div class="span4 stat">
                        <div class="data" align="center">
                            <a href="#userprofile"><span class="number">用户信息</span></a>
                            
                        </div>
                        
                    </div>
                    
                </div>
            </div>-->
            <!-- end upper main stats -->
		
         <div id="pad-wrapper" class="users-list">
		 
		 	<div class="row-fluid header">
                    <h3>设备管理&nbsp;&nbsp;&nbsp;<a id="ViewAllbtn"><i class="icon-refresh"></i></a></h3>
                    <!--<div class="span10 pull-right">
                        <input type="text" class="span5 search" id="Dtext" placeholder="请输入设备ID" />                                               
                        <div class="ui-dropdown">
                            <div class="head" data-toggle="tooltip" title="Click me!" id="search_btn">
                                设备筛选                               
                            </div>  
                        </div>												
                    </div>-->					                    
            </div>
		 	 <div class="row-fluid chart" id="router">
                    <div class="row-fluid head">
                        <div class="span12">
                            <h4 style="margin:0 0 0 0">设备信息 <small>显示当前设备的基本信息</small></h4>
                        </div>
                    </div>
					
					<div class="row-fluid head">
					<div class="span8 header" style="margin-bottom:5px;">
                        <img src="img/contact-profile.png" class="avatar img-circle">
                        <h3 class="name" >当前设备SN：<span id="dev_sn">Alejandra Galván Castillo</span></h3>
                        <span class="area" id="dev_info">Graphic Designer</span>&nbsp;&nbsp;
						<span class="area" id="dev_online">离线</span>
                    </div>
						
					</div>
				</div>
    

				<!--<div class="table-wrapper table-products section" id="subprofile">
                    <div class="row-fluid head">
                        <div class="span12">
                            <h4>子设备信息 <small>管理当前路由器下的子设备</small></h4>
                        </div>
                    </div>
					<div class="row-fluid filter-block">
                        <div class="pull-right">
                            
                            <a class="btn-flat danger" id="sub_btnDelete"><i class="icon-remove"></i>删除子设备</a>&nbsp;&nbsp;
                             <a  id="sub_btnAdd" class="btn-flat success">
                            <span>&#43;</span>
                            添加子设备</a>
                        </div>
                    </div>
					<div class="row-fluid table">
					<table class="table table-hover" id="table-sublist"></table>
					</div>
				</div>-->
				
				
				<div class="table-wrapper table-products section" id="userprofile">
                    <div class="row-fluid head">
                        <div class="span12">
                            <h4 style="margin:0 0 0 0">用户信息 <small>管理与当前设备关联的用户</small></h4>
                        </div>
                    </div>
					<div class="row-fluid filter-block">
                        <div class="pull-right">
                            
                            <a class="btn-flat danger"  id="user_btnDelete"><i class="icon-remove"></i>用户解绑</a>&nbsp;&nbsp;
                             <a  id="user_btnAdd" class="btn-flat success">
                            <span>&#43;</span>
                            添加用户</a>&nbsp;&nbsp;
							<a class="btn-flat"  id="user_export"><i class="icon-save"></i>导出数据</a>
							
                        </div>
                    </div>
					<div class="row-fluid">
					<table class="table table-hover" id="table-userlist"></table>
					</div>
					
				</div>
</div></div></div>

<div class="modal small hide fade" id="devAddModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">添加子设备</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<font style=" font-size:18px; color:#666666; line-height:30px; vertical-align:middle"> 输入设备NID:&nbsp;&nbsp;</font><input type="subdevAddModaltext"  id="text" style=" margin-bottom:0px;" class="form-control" placeholder="Search">
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="devAddModal_addbtn">添加</button>
				</div>
</div>
<div class="modal small hide fade" id="devDeleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">删除子设备</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>将删除全部已选子设备，是否确认删除？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
					<button class="btn btn-danger" data-dismiss="modal" id="devAddModal_delbtn">Delete</button>
				</div>
</div> 
<div class="modal small hide fade" id="userAddModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">添加用户</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<font style=" font-size:18px; color:#666666; line-height:30px; vertical-align:middle"> 输入用户信息:&nbsp;&nbsp;</font><input type="subdevAddModaltext"  id="text" style=" margin-bottom:0px;" class="form-control" placeholder="Search">
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="userAddModal_addbtn">添加</button>
				</div>
</div> 
<div class="modal small hide fade" id="DelOneUserModal" tabindex="-1" role="dialog" aria-labelledby="DelOneUserModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="DelOneUserModalLabel">绑定操作</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>是否将当前用户解除绑定？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="DelOneUserModal_delbtn">确定</button>
				</div>
</div> 
<div class="modal small hide fade" id="roleChangeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="myModalLabel">角色转换</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>是否将当前用户角色转换？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal"  onClick="UserRoleChange(Modname,Modmsk);">确定</button>
				</div>
</div>    
<div class="modal small hide fade" id="userDeleteModal" tabindex="-1" role="dialog" aria-labelledby="userDeleteModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="userDeleteModalLabel">用户解绑</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>是否将当前选中的用户解除绑定?</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="userDeleteModal_delbtn">解绑</button>
				</div>
</div> 
<div class="modal small hide fade" id="UserRoleChooseModal" tabindex="-1" role="dialog" aria-labelledby="UserRoleChooseModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 >用户数据导出</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form id="UserRoleChooseModalform">
					
					<table id="rolechooseTable">
						<tr><td><h4 style="float:left;margin-bottom:10px;">选择管理员</h4></td><td > <select id="UserRoleselect" validate="required" class="input-xlarge"></select></td></tr>						
					</table>													
					</form>
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" id="UserRoleChooseModal_addbtn">导出</button>
				</div>
</div>  
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery-latest.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/cfgmgr/table/bootstrap-table.js"></script>
<script src="js/cfgmgr/table/bootstrap-table-zh-CN.js"></script>
<!--<script src="js/tableExport.js"></script>
<script src="js/jquery.base64.js"></script> -->
<script src="js/jquery-ui-1.10.2.custom.min.js"></script>  
<script src="js/theme.js"></script>
<script src="js/bootbox.min.js"></script>
<script src="js/cfgmgr/validateInput.js"></script>
<script src="js/cfgmgr/TablesOpretor.js"></script>
<script src="js/cfgmgr/map.js"></script>
<script src="js/FileSaver.js"></script>
<script type="text/javascript">
var paramTypemap = new Map();
function validateRow(tableid)
{
    var ispass = $.fn.tables.validateRow(tableid);
     return ispass;
}
function FillSelect(paramTypemap,selectId)
{
	
	$("#" + selectId).empty();
		
		var length = paramTypemap.size();
		
		for ( var i = 0; i < length; i++) {
			
			$("#" + selectId).append("<option value="+paramTypemap.getValue(i)+">"+paramTypemap.getValue(i)+"</option>"); 
	}
	
}
$(function () {
	currRid = requestID();
	currRsn = parent.CurrRouterSn;
	CurrRouterSnOnline = parent.CurrRouterSnOnline;
	if(currRid != 'NO'){ 	
		$("#dev_sn").html(currRsn); 
		$("#dev_info").html("当前设备ID："+currRid);
		if(CurrRouterSnOnline)
			$("#dev_online").html("当前设备状态：在线");
		else
			$("#dev_online").html("当前设备状态：离线");
	}
	else {
		isReLoad = true;
		$("#dev_sn").html(""); 
		$("#dev_info").html("当前设备ID：");
		bootbox.alert("请从‘设备管理’的设备列表中选择设备点击跳入", function() {					
						parent.Reload_devList();
		});	
	}	
//currBindUsers = GetCurrBindUsers();
 GetCurrBindUsers();
$.formInit();	
$('#table-userlist').bootstrapTable({
	method: 'get',
	url: "../orgMgr/user/loadUsers",
	//height: 350,
	striped: true,
	dataType: "json",
	cache: false,
	pagination: true,
	"queryParamsType": "limit",
	singleSelect: false,
	contentType: "application/x-www-form-urlencoded",
	pageSize: 10,
	pageNumber:1,
	showRefresh: false,
	showToggle: false,
	//showHeader: false,
	search: false, //不显示 搜索框
	showColumns: false, //不显示下拉框（选择显示的列）
	sidePagination: "server", //服务端请求
	queryParams: userlistqueryParams,
	responseHandler: userlistresponseHandler,
	columns: [{
                    field: 'state',
                    checkbox: true
         }, 	
		
		{
			field: 'id',	
			title: 'id',	
			width: '15%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},
		{
			field: 'uid',	
			title: '用户ID',	
			width: '25%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		},
		
		{
			field: 'devId',	
			title: '绑定的设备ID',	
			width: '20%',	
			align: 'center',	
			valign: 'middle',	
			sortable: false	
		}/*,
		{
			title: '角色',
			field: 'role',	
			width: '20%',	
			align: 'center',	
			valign: 'middle',
			formatter: roleFormatter,	
			sortable: false	
		}*/,
		{
			title: '绑定',
			field: 'operate',	
			width: '15%',	
			align: 'center',	
			valign: 'middle',	
			formatter: releaseFormatter,				
			sortable: false	
		},
		{
			title: '是否已绑定',
			field: 'isBind',	
			width: '15%',	
			align: 'center',	
			valign: 'middle',	
			formatter: isBindFormatter,				
			sortable: false	
		}
	]
});
	$('#ViewAllbtn').click(function(e){
		e.preventDefault();
		$('#table-userlist').bootstrapTable('refresh');
		
	});
	$("#search_btn").click(function(e){
		e.preventDefault();
		var user = $("#Dtext").val();
		user = '100000101188';
		devControl(user);
			
	});
	$("#router_btn").click(function(e){
		e.preventDefault();
		var info = $("#dev_info").val();
		DevModifyInfo = info;
		user = '100000101156';
		$.ajax({  
               
                url: 'http://localhost:8080/starclouders/manager/device.do?action=getActivate&username='+user, 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{info: info},               
				error : function() {
				 alert("修改路由器备注信息提交数据异常，请重新提交"); 
				},    
                success: devinfoModifyFunction //成功执行方法
				   
     })  
			
	});
	
 $('#sub_btnAdd').click(function (e) {
	 e.preventDefault();
	 $('#devAddModal').modal('show');               
 });
 $('#sub_btnDelete').click(function (e) {
	 e.preventDefault();
	 $('#devDeleteModal').modal('show');               
 });
 $('#user_export').click(function (e) {
 var rows = $('#table-userlist').bootstrapTable('getSelections');
 userObj = [];
 ChoosedUsermap = new Map();
 var role = '2';
 for (var i = 0; i < rows.length; i++) {
	var nid = rows[i].uid + "@nexhome.cn";		
	ChoosedUsermap.put(rows[i].id,rows[i].uid);
	userObj.push({"role": role,"nid": nid});
}
if (userObj.length == 0) {
		alert("请选择需要导出的用户！");
		return;
}	
FillSelect(ChoosedUsermap,'UserRoleselect');
$("#UserRoleselect option[index='0']").attr("selected","selected");
$('#UserRoleChooseModal').modal('show'); 
             
 });
$('#UserRoleChooseModal_addbtn').click(function (e) {
 	
	var ispass = validateRow('rolechooseTable');
	if(!ispass){
			
			return false;
	}
	var role = $("#UserRoleselect").val() + "@nexhome.cn";
	var nid;
	$.each(userObj,function(index,item){
		if(item.nid == role){
			nid = item.nid;
			userObj.splice(index, 1);
			return false;
		}
			
	})
	var adm = '1';
	userObj.push({"role": adm,"nid": nid});
	var Export = [];
	Export.push({"User": userObj});
	var blob = new Blob([JSON.stringify(Export[0])], {type: "text/plain;charset=utf-8"});
	saveAs(blob, "User.json");
 	
	$('#UserRoleChooseModal').modal('hide');
	bootbox.alert("导出数据成功，请至浏览器的下载路径中查看", function() {					
						//return;
	});	
});
 $('#user_btnDelete').click(function (e) {
	 e.preventDefault();
	 $('#userDeleteModal').modal('show');               
 });
 $('#user_btnAdd').click(function (e) {
			
	 $.ajax({  
               
                url: '../orgMgr/user/addUser', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{devId: currRid},               
				error : function() {
				 alert("获取数据异常，请重新获取"); 
				},    
                success: function(data){
					if(data.resultCode != '10000'){
						
						bootbox.alert(data.resultMsg, function() {					
						//return;
						});	
						
					}
					else{
						bootbox.alert(data.resultMsg, function() {
						$('#table-userlist').bootstrapTable('refresh');
						});	
												
					}
					 
				}
				   
     })  
	              
});
$('#userDeleteModal_delbtn').click(function (e) {
	
	var ids = "";
	var rows = $('#table-userlist').bootstrapTable('getSelections');
	for (var i = 0; i < rows.length; i++) {
		ids += rows[i].id + ',';
	}
	ids = ids.substring(0, ids.length - 1);
   
	if (ids == "") {
		alert("请选择您要删除的记录！");
		return;
	}	
	 $.ajax({  
               
                url: '../orgMgr/user/removeUser', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{id: ids},               
				error : function() {
				 alert("获取数据异常，请重新获取"); 
				},    
                success: function(deldata){
						if(deldata.resultCode != '10000'){					
						$('#devDeleteModal').modal('hide');
						
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 $('#devDeleteModal').modal('hide'); 
						 bootbox.alert(deldata.resultMsg, function() {					
							$('#table-userlist').bootstrapTable('refresh');
						});		
					 	
					 }
					 
				}
				   
     })  
	              
});	

$('#userAddModal_addbtn').click(function (e) {
	var nid = $("#dev_info").val();
	nid = '100000101156';
		
	 $.ajax({  
               
                url: 'http://localhost:8080/starclouders/manager/device.do?action=getActivate&username='+nid, 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{username: nid},               
				error : function() {
				 alert("获取数据异常，请重新获取"); 
				},    
                success: function(){
					 $('#userAddModal').modal('hide');
					 $('#table-userlist').bootstrapTable('refresh');
				}
				   
     })  
	              
});
$('#userAddModal_delbtn').click(function (e) {
	var nid = $("#dev_info").val();
	nid = '100000101156';
	var ids = "";
	var rows = $('#table-userlist').bootstrapTable('getSelections');
	for (var i = 0; i < rows.length; i++) {
		ids += rows[i].id + ',';
	}
	ids = ids.substring(0, ids.length - 1);
   
	if (ids == "") {
		alert("请选择您要删除的记录！");
		return;
	}	
	 $.ajax({  
               
                url: 'http://localhost:8080/starclouders/manager/device.do?action=getActivate&username='+nid, 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{username: ids},               
				error : function() {
				 alert("获取数据异常，请重新获取"); 
				},    
                success: function(){
					 $('#userDeleteModal').modal('hide'); 
					 $('#table-userlist').bootstrapTable('refresh');
				}
				   
     })  
	              
});	
	
});

function DelOneUserDiv(oneUser)
{
	
	$('#DelOneUserModal').modal('show');
	$("#DelOneUserModal_delbtn").attr("onclick","DelOneUser(\'"+ oneUser +"\')");
	 	 
}
function BindOneUser(oneUser,devId)
{
	$.ajax({  
               
                url: '../orgMgr/user/bindUser', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{id: oneUser,devId:devId},
				error : function() {
				
				 bootbox.alert("绑定账户数据异常", function() {					
							//return;
						});
				},    
                success: function(deldata){
					if(deldata.resultCode != '10000'){											
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 bootbox.alert(deldata.resultMsg, function() {												
							//currBindUsers = GetCurrBindUsers();
							 GetCurrBindUsers();
                            $('#table-userlist').bootstrapTable('refresh');
						});		
					 	
					 }
					
				}               
								   
     })  
	 	 
}
function DelOneUser(oneUser)
{
	
	 $.ajax({  
               
                url: '../orgMgr/user/removeUser', 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{id: oneUser},
				error : function() {
				
				 bootbox.alert("删除账户数据异常", function() {					
							//return;
						});
				},    
                success: function(deldata){
					if(deldata.resultCode != '10000'){					
						$('#DelOneUserModal').modal('hide');
						
						bootbox.alert(deldata.resultMsg, function() {					
							//return;
						});						
					}
					else{
						 $('#DelOneUserModal').modal('hide'); 
						 bootbox.alert(deldata.resultMsg, function() {					
							$('#table-userlist').bootstrapTable('refresh');
						});		
					 	
					 }
					
				}               
								   
     })  
}
function UserRoleChange(Modname,Modmsk)
{
nid = '100000101156';
	$.ajax({  
               
                url: 'http://localhost:8080/starclouders/manager/device.do?action=getActivate&username='+nid, 
                type: 'GET',  
                dataType: 'json',  
                timeout: 10000,  
                cache: false,
				data:{username: name,mask: msk},               
				error : function() {
				 alert("获取数据异常，请重新获取"); 
				},    
                success:  function() {
				 	 $('#roleChangeModal').modal('hide'); 
					 $('#table-userlist').bootstrapTable('refresh'); 
				}
     })  
}
function ChangeRole(name,msk)
{
	 $('#roleChangeModal').modal('show');
	 if(msk == '1'){
		$('#roleChangeModal .modal-body .error-text').html("是否确定将用户" + name +"切换为普通用户？")
		Modname = name;
		Modmsk = '0';
	}
	else{
		$('#roleChangeModal .modal-body .error-text').html("是否确定将用户" + name +"切换为管理员？")
		Modname = name;
		Modmsk = '1';
	}
					
	    
}
function responseHandler(res) {
	return {
	"rows": res.Rows,
	"total": res.Total
	};

}
//传递的参数
function queryParams(params) {
	return {
		pagesize: params.limit,
		page: params.pageNumber,
		devId: currRid
	};
}
function getLicenseFormatter(value, row, index) {
	return '<button class="btn" onclick="GetLicenseFrom(\''+ row.sn+'\')">获取</button>'
}

function sublistresponseHandler(res) {
	
	return {
	"rows": res,
	"total": res.length
	};

}
//传递的参数
function sublistqueryParams(params) {
	return {
		pagesize: params.limit,
		page: params.pageNumber,
		devId: currRid
	};
}

function operateFormatter(value, row, index) {
            return [/*'<a target="mainIframe" title="点击跳转到该设备的设备管理页" onclick="JumpTOOAMPage(\''+ row.sn+'\')"><i class="icon-pencil"></i></a>',*/
					'<a href="#myModal" role="button" data-toggle="modal"><i class="icon-remove"></i></a>'
                    ].join('');
}


function userlistresponseHandler(res) {
	
	return {
	"rows": res.data.rows,
	"total": res.data.total
	};

}
//传递的参数
function userlistqueryParams(params) {
	return {
		pagesize: params.limit,
		page: params.pageNumber,
		devId: currRid
	};
}
function roleFormatter(value, row, index) {
return '<button class="btn btn-primary" data-toggle="button" onclick="ChangeRole('+ row.username+ ',1' +')">切换角色</button>';           
}
function releaseFormatter(value, row, index) {
           /*return ['<ul class="actions"><li class="last" onclick="DelOneUserDiv(\''+ row.id+'\')"><i class="table-delete"></i></li></ul>'
							].join('');*/
	if (isBindUser(row.uid) == true) {
	    return ['<button style="display:none" class="btn-flat danger" data-toggle="button" onclick="DelOneUserDiv(\''+ row.id+'\')">解绑</button>',
	        '<button style="display:none" class="btn-flat success" data-toggle="button" onclick="BindOneUser(\''+ row.uid+'\',\''+ row.devId+'\')">绑定</button>'
							].join('');	
	}
	else {
	    return ['<button style="display:none" class="btn-flat danger" data-toggle="button" onclick="DelOneUserDiv(\''+ row.id+'\')">解绑</button>',
	        '<button class="btn-flat success" data-toggle="button" onclick="BindOneUser(\''+ row.uid+'\',\''+ row.devId+'\')">绑定</button>'
							].join('');	
	}
						
}
function isBindFormatter(value, row, index) {
    var content = "否";
    try {
        if (isBindUser(row.uid) == true) {
        content = "是";
        
        if (isManagerUser(row.uid) == true) {
        content += "【管理员】";
        }
    }
    } catch (e) {
        content = "failed";
    }
    
    return content;           
}
function isBindUser(uid)
{
    var isBind = false;
    for (var i=0; i<currBindUsers.length; i++) {
        if (uid == currBindUsers[i].username) {
            isBind=true;
            break;
        }
    }
    return isBind;
}
function isManagerUser(uid)
{
    var isManager = false;
    for (var i=0; i<currBindUsers.length; i++) {
        if (uid == currBindUsers[i].username) {
            if (currBindUsers[i].role == "1") {
                isManager = true;
                break;
            }
        }
    }
    return isManager;
}
</script>
</body>
</html>


